/**
 * 添加或者修改页面
 */
var FiCarrierFreightInfoInfoDlg = {
    data: {
        startDt: "",
        endDt: "",
        carrierId: "",
        carrierUserId: "",
        carrierName: "",
        lineId: "",
        lineName: "",
        kilometer: "",
        sumNum: "",
        sumVol: "",
        freightMoney: "",
        loadingMoney: "",
        custComplaint: "",
        otherFines: "",
        otherSubsidie: "",
        stat: "",
        remark: "",
        deliverId: "",
        deptId: "",
        createTime: "",
        createUser: "",
        operateId: "",
        operateName: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    laydate.render({
        elem: '#startDt'
        ,value:new Date(),
        done: function(value, date, endDate){
            getYunFei();
        }
    });

    laydate.render({
        elem: '#endDt'
        ,value:new Date(),
        done: function(value, date, endDate){
            getYunFei();
        }
    });



    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/fiCarrierFreightInfo/addItem", function (data) {
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/fiCarrierFreightInfo'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/fiCarrierFreightInfo'
    });

    form.on('select(operateId)', function(data) {
        getYunFei();
    });

    form.on('select(carrierId)', function(data) {
        getYunFei();
    });

    form.on('select(lineId)', function(data) {
        getYunFei();
    });


    function getYunFei(){
        var operateId = $("#operateId").val();
        var carrierId = $("#carrierId").val();
        var lineId = $("#lineId").val();
        var startDt = $("#startDt").val();
        var endDt = $("#endDt").val();
        if(operateId == null || operateId == ''){
            return;
        }
        if(carrierId == null || carrierId == ''){
            return;
        }
        if(lineId == null || lineId == ''){
            return;
        }
        if(startDt == null || startDt == ''){
            return;
        }
        if(endDt == null || endDt == ''){
            return;
        }
        var queryData = {};
        queryData['operateId'] = operateId;
        queryData['carrierId'] = carrierId;
        queryData['lineId'] = lineId;
        queryData['startDt'] = startDt;
        queryData['endDt'] = endDt;

        $.ajax({
            type: "POST",
            url: Feng.ctxPath + "/fiCarrierFreightInfo/getYunFei",
            dataType:'json',
            data: queryData,
            beforeSend: function () {
                //弹出加载中
                index = layer.load(1, {
                    shade: [0.3, '#000'] //0.1透明度的白色背景
                });
            },
            success: function (data) {
                layer.close(index);
                if(data.success){
                    $("#kilometer").val(data.data.kilometer)
                    $("#sumNum").val(data.data.sumNum)
                    $("#sumVol").val(data.data.sumVol)
                    $("#freightMoney").val(data.data.freightMoney)
                    $("#loadingMoney").val(data.data.loadingMoney)
                }
            },
            error: function (data) {
                console.log(data)
            }
        });
    }
});